import * as constants from './constants';
import { fromJS } from 'immutable';

const defaultState=fromJS({
    list:[],
    loading:true,
    total:0,
    emptyText:'暂无数据',
    fielddata:{
        arr:[
            'pid','name','dirname','thumb'
            ,'keyword','description','template'
            ,'status','sort'
		],
        pid:{type:'select.tree',title:'上级栏目',name:'pid',placeholder:"请选择(默认顶级)",treeData:[]}
        ,name:{type:'input',title:'栏目名称',name:'name',autoFocus:true,placeholder:"请输入栏目名称",rules:[{
            required: true,
            message: '栏目名不能为空'
        }]}
        ,dirname:{type:'input',title:'英文名',name:'dirname',placeholder:"请输入英文名"}
        ,thumb:{type:'upload',title:'缩略图',name:'thumb',length:1,data:{path:'news',size:6}}
        ,keywords:{type:'input',title:'关键字',name:'keywords',placeholder:"输入关键字"}
        ,description:{type:'text',title:'描述',name:'description',rows:4,placeholder:"请输入描述"}
        ,template:{type:'input',title:'模板文件',name:'template',placeholder:"请输入模板文件名,栏目默认为catgory"}
        ,status:{type:'radio',title:'状态',name:'status',options:[
            {value:1,name:'启动'},
            {value:0,name:'禁用'}
        ]}
        ,sort:{type:'input.number',title:'排序',name:'sort',min:0,placeholder:"0"}
    },
    catetree:[]
});
export default (state=defaultState,action)=>{
    switch (action.type) {
        case constants.LIST:
            return state.merge({
                list : fromJS(action.list),
                total : action.total
            })
        case constants.LOADING:
            return state.merge({
                loading : action.loading
            })
        case constants.CATETREE:
            return state.merge({
                catetree : fromJS(action.catetree)
            })
        case constants.NOAUTH:
            return state.merge({
                emptyText : action.emptyText
            })
        default:
    }
    return state;
}